import mean from "./mean.js";
import sampleStandardDeviation from "./sample_standard_deviation.js";

/**
 * `变异系数`_ 是标准差与均值的比值。
 * .._`变异系数`: https://en.wikipedia.org/wiki/Coefficient_of_variation
 *
 *
 * @param {Array} x 输入数据
 * @returns {number} 变异系数
 * @example
 * coefficientOfVariation([1, 2, 3, 4]).toFixed(3); // => 0.516
 * coefficientOfVariation([1, 2, 3, 4, 5]).toFixed(3); // => 0.527
 * coefficientOfVariation([-1, 0, 1, 2, 3, 4]).toFixed(3); // => 1.247
 */
function coefficientOfVariation(x) {
    return sampleStandardDeviation(x) / mean(x);
}

export default coefficientOfVariation;
